Hello and welcome back to the costs on the last session we learned about basic data types like integers
floats and strings.
And also we learned about basic operations like addition multiplication and so on.
And now in this session we are introducing where I was.
So what is the variety.
Let's assume we have an immediate object five.
We can print it out and instead of having the five as the number itself we can assign a variety of let's
call it a.
So a equals five
in Python now makes internally a reference that whenever we call a meets calculating five for its its
returning five.
So if we now just print a we are getting five.
So A stands for five.
And as we learned in the last session we can also print out a by calling the print function.
So that's actually the same and we can also change the reference so if we say OK if I was five but now
a seven we can just change it.
So a seven and let's check if A's now seven and eight seven now.
So we can simply change our reference so before our reference was to five to the integer object five
and now a reference is to seven.
So we can change for the reference all right.
So let's introduce another variable let's call it B B equals 2 and we can also print out b b as to and
then the last lesson we have learned that if you want to print out both A and B and one cell
so by default to put a notebook only print out the last statement or the last line that's B here.
So now if you want to print out both we have to call the print function
and A and B.
So now we can print out both 7 and 2.
All right.
So basically we can do with varietals the same as with integers or floats.
We can do the basic operations like additions so we can take a plus b s nine A minus B S five B minus
a minus five B can also multiply so A times B and we can of course we can also divide a divided by B
and 0 for example we can assign the result of a divided by B
so it's three point five we kind of can assign a new override but see to it.
So C equals a divided by B.
Let's print out C So c is three point five and we can also check the data type of C.
So I would expect that it's a float.
Yes exactly.
And of course we cannot only assign over either to an integer or an end and float.
We can also assign a rival to an end String object.
So for example we have dark and we can assign the right of a d d equals stock and we can of course print
out D so D.
So internally a person makes a reference from the right a deed to our string object talk.
So these stock and we can also check the data type of D.
And it's a string so dark dog is a string of costs and the idea's referencing to talk and there's also
a string then and former Ibo name we can actually make any name we we we want to have so we can say
my favorite dog is Lassie for example and this works.
Now if I want to print out my variable my favorite dog I can start typing my end by pressing the tab
key.
Supplies and automatically completes my where I ever saw my wife Leslie is oh that's called the tab
completion supplies.
Knows that a variable caught my favorite dog is start.
Um yeah internally and whenever I start typing my then I can press tap and um yeah Python automatically
um yeah completes my my arrival.
So that's that's quite helpful actually when when the rivals.
This is quite long like here in that case and I what I would also like to highlight this and that I
need the under slash here.
So if it's just a space my favorite dog so that's that cannot serve as a rival.
So here it gives me an error message.
So space space is not defined as us as part of a rival actually.
So the only works in this way
and also a string itself like let's say Doc a string like DA cannot be in our arrival so dark equals
Spike
gets me as well and an error message.
N on into da float cannot be in viable.
So let's say 5 equals Spike let's say it also doesn't work but an integer can be part often variety.
So let's say dark 5 is a spike.
So that works
and that's one last thing I want to highlight here.
So let's assume I assign to the variable E equals 10
so we use 10 and then I assign F equals E Oh sorry F equals E sum this case f is 10 because E M and
F equals E so f also must be 10.
And now if I change E.
So before you reference was a reference to the object 10.
If I change e to let's say 15 and I again check the reference of F F is 13.
Even if I before I referenced F equals E.
So what happened internally so internally here and not object 10 was created and then reference.
And it was reference to the variable e and here and we say F equals E then internally a reference to
the same object 10 was created to F so we have one object an integer 10 and we have two references from
tend to we and 2 F and if you change here the reference to 15 internally a new object 15 is created
and the reference for you was changed from 10 to 15 but there was no impact on F so the reference from
F is still to the integer object 10 not to 15 so that's that's quite important to understand due out
how Python works internally all right.
So that's it.
So thank you very much.
And um yeah.
Hope you enjoyed it.
And uh see you in the next lesson.